<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('公告列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="searchText" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="sysNotice-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="sysNotice-table" lay-filter="sysNotice-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="sysNotice-bar">

    <button class="pear-btn pear-btn-warming pear-btn-md" lay-event="view" title="查看"><i class="layui-icon layui-icon-template"></i>
    </button>


</script>


<script type="text/html" id="sysNotice-type">
    {{#if (d.type == '1') { }}
    <span class="layui-badge layui-bg-blue">一般</span>
    {{# }else if(d.type == '2'){ }}
    <span class="layui-badge layui-bg-orange">重要</span>
    {{# } }}
</script>

<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        let MODULE_PATH = rootPath+"/SysNoticeController/";
        let cols = [
            [
                 {type: 'checkbox'},
                {title: 'ID', field: 'id', align: 'center'},
                {title: '标题', field: 'title', align: 'left'},
                {title: '内容', field: 'content', align: 'left'},
                {title: '类型', field: 'type', align: 'center',toolbar: '#sysNotice-type'},
                {title: '创建人', field: 'createUsername', align: 'left'},
                {title: '创建时间', field: 'createTime', align: 'left'},
                {title: '操作', toolbar: '#sysNotice-bar', align: 'center'}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#sysNotice-table',
            url: MODULE_PATH + 'list',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#role-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        //table图标事件绑定
        table.on('tool(sysNotice-table)', function (obj) {
           if (obj.event === 'view') {
                window.view(obj);
            }
        });


        //查询按钮绑定
        form.on('submit(sysNotice-query)', function (data) {
            table.reload('sysNotice-table', {where: data.field})
            return false;
        });



        //查看
        window.view = function (obj) {
            layer.open({
                type: 2,
                title: '查看',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'viewinfo/' + obj.data['id']
            });

        }

        //刷新按钮
        window.refresh = function () {
            table.reload('sysNotice-table');
        }
    })
</script>
</html>